using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace whereIsTheDonutGame
{
    /// <summary>
    /// A movable Box to activate triggers and stuff
    /// </summary>
    public class MovableBoxSpawner : Microsoft.Xna.Framework.DrawableGameComponent
    {
                private ICamera camera;
        private List<MovableBox> boxes;

        public MovableBoxSpawner(Game game)
            : base(game)
        {
            boxes = new List<MovableBox>();

        }


        public override void Initialize()
        {

             camera = (ICamera)Game.Services.GetService(typeof(ICamera));
            base.Initialize();
        }


        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            foreach (MovableBox b in boxes)
            {
               foreach (ModelMesh mesh in b.Model.Meshes)
               {
                   foreach (BasicEffect effect in mesh.Effects)
                        {
                            effect.View = camera.ViewMatrix;
                            effect.Projection = camera.ProjectionMatrix;
                            effect.World = Matrix.CreateTranslation(b.Position);
                        }
                        mesh.Draw();
                    }
                    base.Draw(gameTime);
                    b.UpdateBoundingBox();
                }
                
            }
        }
}
